local dingce = fk.CreateSkill {
  name = "dingce",
}

dingce:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player == target and player:hasSkill(self) and not player:isKongcheng() and data.from
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#dingce-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id1 = room:askForDiscard(player, 1, 1, false, self.name, false, nil, "#dingce-discard1", true)[1]
    if not id1 then return end
    room:throwCard({id1}, self.name, player, player)
    if player.dead or data.from.dead or data.from:isKongcheng() then return end
    room:doIndicate(player.id, {data.from.id})
    local id2 = room:askForCardChosen(player, data.from, "h", self.name)
    room:throwCard({id2}, self.name, data.from, player)
    if player.dead or Fk:getCardById(id1).color ~= Fk:getCardById(id2).color or Fk:getCardById(id1).color == Card.NoColor then return end
    room:useVirtualCard("foresight", nil, player, {player}, self.name)
  end,
})

return dingce